package com.sy.controller.permissions;

import com.sy.bean.permissions.role.Role;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.service.permissions.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "角色权限管理")
@RequestMapping("/api/role")
public class RoleController extends BaseController {
    @Autowired
    RoleService roleService;
    @ApiOperation("角色列表")
    @GetMapping("/list")
    public ResultBean query(){
        List list = roleService.queryList(null);
        return success("角色列表",list);
    }
    @ApiOperation("新增角色")
    @PostMapping("/insert")
    public ResultBean insert(@RequestBody Role role){
        int rs = roleService.save(role);
        return gotoResult(rs,"添加");
    }
    @ApiOperation("修改角色信息")
    @PutMapping("/update")
    public ResultBean update(@RequestBody Role role){
        int rs = roleService.update(role);
        return gotoResult(rs,"修改");
    }
    @ApiOperation("删除角色")
    @GetMapping("/delete")
    public ResultBean insert(int id){
        int rs = roleService.delete(id);
        return gotoResult(rs,"删除");
    }
    @ApiOperation("修改状态")
    @PutMapping("/update/edit/status")
    public ResultBean editStatus(@RequestBody Role role){
        int rs = roleService.editStatus(role);
        return gotoResult(rs,"修改");
    }
    @ApiOperation("查询角色授权菜单")
    @GetMapping("/update/edit/menuId")
    public ResultBean editStatus(int id){
        List<Integer> rs = roleService.queryMenuId(id);
        return success("授权菜单",rs);
    }
}
